/**
 * @ author: 汪孟苹
 */
define(["jquery","bbcare","comm/datatable/datatable","bch/app/patientManager/warnFollowupList.ui"],function($,$bb,$datatable,$ui){
    var servers = {};

    var URL = $bb.baseUrl("followapp");
    var doctorName = JSON.parse($bb.getSessionStorage("account")).alias;
    
    /* 请求队列queue */
    servers.ajaxQueue = function(callback){
        $bb.ajax({
            url: URL + "ctrl/projectManage/qryProjectQueue",
            success: function(data){
                if(data.success){
                    callback(data.data);
                }else{
                    $bb.toastShow(data.msg ? data.msg : "请求队列出错！");
                }
            }
        });
    }
    
    /******************** 以下是datatable ********************/

    /**
     * 入参
     */
    var inParams = function(args){
        var params = $bb.getPageParams();
        var data = JSON.stringify({
            data: {
                "args": JSON.stringify(args),
                "busiTypeList":params.busiTypeList,
                "hisNo": $.trim($("#hisNo").val()),
                "userName": $.trim($("#userName").val()),
                "phoneNo": $.trim($("#phoneNo").val()),
                "queueId": $("#queue").val(),
                "beginDate": $("#timeFrom").val(),
                "endDate": $("#timeTo").val(),
                "sendStatus": $("#status").val(),
            }
        });
        return data;
    }
    /**
     * 出参
     */
    var outParams = function(data){
        return data.rows;
    }
    /**
     * columns
     */
    var columnsHisNo = function(e){
        return e.hisNo ? e.hisNo : e.hisNo1 ? e.hisNo1 : e.hisNo2 ? e.hisNo2 : "-";
    }
    var columnsSendStatus = function(e){
        return e.sendStatus == "1" ? "成功" : "失败";
    }
    var columnsData = function(){
        var columnsArr = [
            {"data":columnsHisNo},
            {"data":'userName'},
            {"data":'phoneNo'},
            {"data":'birthday'},
            {"data":'queueName'},
            {"data":'nodeName'},
            {"data":'sendTime'},
            {"data":columnsSendStatus},
            {"data": 'reminderType'},
        ];
        return columnsArr;
    }
    /**
     * 初始化完成之后的回调函数
     */
    var initComplete = function(setting,json){
        var id = $(".layout-bottom table").attr("id");
        $("#" + id).prev("div.row").remove();
        // 搜索 
        $("#serchBtn").click(function(){
            $datatable.table.api().ajax.reload();  // 出发dt的重新加载数据的方法
            var args = $datatable.table.api().ajax.params();   //获取dt请求参数 
        });
    }
    /**
     * 获取datatable里的options
     */
    servers.getOptions = function(){
        var sessionId = $bb.getSessionStorage("sessionId");
        var options = {
            "ajax": {
                "url": URL + "ctrl/processManage/qryReminderRecord?sessionId=" + sessionId,
                "data": inParams,
                "dataSrc": outParams
            },
            "columns": columnsData(),
            "initComplete": initComplete,
        };
        return options;
    }

    return servers;
});